package com.ssm.design.observer.listener;

import com.ssm.design.observer.event.OrderSuccessEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;


@Slf4j
@EnableAsync
@Configuration
public class OrderSuccessListener implements ApplicationListener<OrderSuccessEvent> {


    @Override
    public void onApplicationEvent(OrderSuccessEvent orderSuccessEvent) {
        log.info("default order success listener ....");
    }

    @EventListener(OrderSuccessEvent.class)
    public void dispatchCar(OrderSuccessEvent orderSuccessEvent) {
        log.info("dispatch car listener .... {}", orderSuccessEvent.getObject());
    }

    @Async
    @EventListener(OrderSuccessEvent.class)
    public void asyncDispatchCar(OrderSuccessEvent orderSuccessEvent) {
        log.info("async dispatch car listener ...." + orderSuccessEvent.getObject());
    }
}
